<?php
/**
 * Created by PhpStorm.
 * User: 94004
 * Date: 2017/12/28
 * Time: 19:52
 */
header("Content-Type:text/html;charset=utf-8;");
require_once "../util/db_helper.php";
if (!empty($_POST)) {
    $email = $_POST["email"];
    $password = $_POST["password"];
    $sql = " SELECT * FROM users u WHERE email= '{$email}'";
    $res = query($sql);
    $arr = array("code" => 101, "msg" => "登录失败，请重新登录");
    if (!empty($res)) {
        if ($res[0]["password"] == $password && $res[0]["status"] == 1) {
            $arr["code"] = 100;
            $arr["msg"] = "登录成功";
            $arr["user_id"] = $res[0]["id"];
            session_start();
            $_SESSION["user_id"] = $res[0]["id"];
        }
    }
    echo json_encode($arr, JSON_UNESCAPED_UNICODE);
}
?>